<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>按时间问好</title>

    <style>
        img{

            width : 500px;
        }
    </style>
</head>
<body>

    <img src="img/1.jpg" alt="早上好">

    <div>早上好！！</div>

    <script>
        var img = document.querySelector('img');
        var div = document.querySelector('div');

        var time = new Date();
        var h = time.getHours();

        if (h < 12) {

            img.src = "img/1.jpg";
            div.innerHTML = "早上好！！";

        } else if(h < 18) {
            img.src = "img/2.jpg";
            div.innerHTML = "下午好！！";
        } else {
            img.src = "img/3.jpg";
            div.innerHTML = "晚上好！！";
        }



    </script>
</body>
</html>